package com.ruoyi.web.controller.community;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.domain.CmtWork;
import com.ruoyi.community.service.ICmtWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/community/work")
public class CmtWorkController extends BaseController {

    @Autowired
    private ICmtWorkService iCmtWorkService;

    /**
     * 获取岗位列表信息
     */

    @PreAuthorize("@ss.hasPermi('community:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmtWork work){
        startPage();
        List<CmtWork> list = iCmtWorkService.selectWorkList(work);
        return getDataTable(list);
    }

    /**
     * 新增岗位信息
     */
    @PreAuthorize("@ss.hasPermi('community:work:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CmtWork work)
    {

        work.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCmtWorkService.insertWork(work));
    }

    /**
     * 修改岗位号
     */
    @PreAuthorize("@ss.hasPermi('community:work:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CmtWork work)
    {

        work.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iCmtWorkService.updateWork(work));
    }

    /**
     * 根据岗位编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:work:query')")
    @GetMapping(value = "/{workId}")
    public AjaxResult getInfo(@PathVariable Long workId)
    {
        return AjaxResult.success(iCmtWorkService.selectWorkById(workId));
    }

    /**
     * 删除岗位
     */
    @PreAuthorize("@ss.hasPermi('community:work:remove')")
    @Log(title = "岗位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{workIds}")
    public AjaxResult remove(@PathVariable Long[] workIds)
    {
        return toAjax(iCmtWorkService.deleteWorkByIds(workIds));
    }

    /**
     * 获取岗位选择框列表
     */
    @GetMapping("/optionselect")
    public AjaxResult optionselect()
    {
        List<CmtWork> works = iCmtWorkService.selectWorkAll();
        return AjaxResult.success(works);
    }




}
